package com.asit.service.impl;

import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.kafka.support.KafkaHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
@Slf4j
public class KafkaConsumer {

    @KafkaListener(topics = "mtytopic",groupId = "mlkj-group")
    public void gnlk(ConsumerRecord<?,?> record, @Header(KafkaHeaders.RECEIVED_TOPIC) String topic){
        Optional<Object> message = Optional.ofNullable(record.value());
        log.info("A={}={}", DateUtil.format(DateUtil.date(record.timestamp()),"yyyy-MM-dd HH:mm:ss"),message.get());
        /*if(message.isPresent()){
            Object msg = message.get();
            //log.info("{}",topic);
            log.info("{}",msg);
        }*/
    }
}
